//
//  DHWashingCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/14.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHWashingCell.h"

@interface DHWashingCell()

@property (strong, nonatomic) NSDictionary *dic;

@end

@implementation DHWashingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.cartButton.layer.cornerRadius = self.cartButton.height / 2;
    
    WeakSelf(weakSelf)
    [self.cartButton bk_addEventHandler:^(id sender) {
        NSInteger count = [weakSelf.countLabel.text integerValue];
        if (count > 0) {
            [[DHNetAPIClient shareDHNetAPIClient] request_cart_addWithParams:@{@"type":@"洗衣",@"object":[weakSelf.dic objectForKey:@"_id"],@"count":@(count)} andBlock:^(id data, NSError *error) {
                if (data) {
                    [NSObject showHudTipStr:@"添加成功"];
                }
            }];
        }else{
            [NSObject showHudTipStr:@"请添加一件衣物"];
        }
    } forControlEvents:UIControlEventTouchUpInside];
}

- (IBAction)addAction:(id)sender {
    NSInteger count = [self.countLabel.text integerValue] + 1;
    self.countLabel.text = [NSString stringWithFormat:@"%ld",(long)count];
    
    self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[self.dic objectForKey:@"wash_price"] floatValue] * count];
}

- (IBAction)jianAction:(id)sender {
    NSInteger count = [self.countLabel.text integerValue] - 1;
    if (count <= 0) {
        return;
    }else{
        self.countLabel.text = [NSString stringWithFormat:@"%ld",(long)count];
        self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[self.dic objectForKey:@"wash_price"] floatValue] * count];
    }
}

- (void)updateCell:(NSDictionary *)dic{
    self.dic = dic;
    [self.imgView dh_setImageURLString:[dic objectForKey:@"icon"]];
    self.nameLabel.text = [dic objectForKey:@"title"];
    self.leftPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[dic objectForKey:@"wash_price"] floatValue]];
    self.rightPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[dic objectForKey:@"wash_price"] floatValue]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
